#ifndef _AC_COMMON_OSTREAM_HPP_
#define _AC_COMMON_OSTREAM_HPP_

#include <cstdarg>

#include "common/parm_string.hpp"

class OStream
{
public:
    virtual void write(char c) = 0;
    virtual void write(ParmStr) = 0;
    virtual void write(const void *, unsigned int) = 0;

    virtual int vprintf(const char* format, va_list ap) = 0;

    int printf(const char* format, ...)
    {
        va_list ap;
        va_start(ap, format);
        
        int result = vprintf(format, ap);

        va_end(ap);
        return result;
    }

    void put(char c)
    {
        write(c);
    }

    void put(ParmStr str)
    {
        write(str);
    }

    virtual void printl(ParmStr l)
    {
        write(l);
        write('\n');
    }

    void write16(unsigned short v)
    {
        write(&v, 2);
    }
    
    void write32(unsigned int v)
    {
        write(&v, 4);
    }

    OStream& operator << (char c)
    {
        write(c);
        return *this;
    }

    OStream& operator << (ParmStr in)
    {
        write(in);
        return *this;
    }

    virtual ~OStream()
    {
    }
};

#endif  // _AC_COMMON_OSTREAM_HPP_
